#include "comm.h"

int main()
{
    // 调用创建管道文件函数
    int ret = createFilo(NAME_PIPE);
    assert(ret);
    (void)ret;

    printf("server begin\n");
    // 以读方式打开管道文件
    int rfd = open(NAME_PIPE, O_RDONLY);
    printf("server end\n");
    if (rfd < 0)
        exit(1);

    char buffer[1024];
    while (1)
    {
        /* code */
        ssize_t s = read(rfd, buffer, sizeof(buffer) - 1);
        if (s > 0)
        {
            buffer[s] = 0;
            printf("client->server#%s", buffer);
        }
        else if (s == 0)
        {
            printf("client quit, me too!%s", buffer);
            break;
        }
        else
        {
            printf("err string%s", errno);
        }
    }

    close(rfd);
    // sleep(10);
    // 移除管道文件函数
    removeFifo(NAME_PIPE);
    return 0;
}